import 'dart:io';

import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_member/utils/Counter.dart';
import 'package:flutter_member/utils/service_locator.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';
import 'package:provide/provide.dart';

import 'config/application_constants.dart';
import 'routes/application.dart';
import 'routes/routess.dart';

void main() async{
  setupLocator();
  WidgetsFlutterBinding.ensureInitialized();
  await AmapLocation.instance.init(iosKey: '055dfc9776e6af32ecf887149ae87b68');
  var counter =Counter();
  var providers  =Providers();
  providers..provide(Provider<Counter>.value(counter));
  runApp(ProviderNode(
    child: MyApp(),
    providers: providers,
  ));
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
    const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initData();
  }

  Future<void> initData() async {
    // 初始化儲存庫
    await Parse().initialize(keyParseApplicationId, keyParseServerUrl,
        masterKey: keyParseMasterKey, // Back4App和其他
        debug: true,
        autoSendSessionId: true,
        coreStore: await CoreStoreSharedPrefsImp.getInstance());
    final ParseResponse response = await Parse().healthCheck();
  }
  @override
  Widget build(BuildContext context) {

//    ScreenUtil.init(context, designSize: Size(375, 667), allowFontScaling: false);
    //-----------------路由主要代码start
    final router = Router();
    Routess.configureRoutes(router);
    Application.router = router;
    //-----------------路由主要代码end

    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      //-----------------路由主要代码start
      initialRoute: '/',
      onGenerateRoute: Application.router.generator,
      //-----------------路由主要代码end

    );
  }
}


